<#assign ctx=request.contextPath />
<!doctype html>
<html class="no-js fixed-layout">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>使用app注册</title>
<meta name="keywords" content="index">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" href="${ctx}/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${ctx}/bootstrap/css/bootstrap-table.min.css" />
<style type="text/css">
</style>
</head>
<body>
	<div class="container">
		<div class="row">
			<div class="col-sm-12 col-md-12 col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">
						<h3 class="panel-title">使用app注册</h3>
					</div>
					<div class="panel panel-body">
						<div class="col-sm-10 col-md-10 col-lg-12">
							<form class="form-horizontal" id="registerForm">
							  <div class="form-group">
							    <label class="col-sm-2 control-label">AppCode</label>
							    <div class="col-sm-10">
							      <input type="text" class="form-control" id="appCode" name="appCode" placeholder="AppCode" maxlength="10">
							    </div>
							  </div>
							  <div class="form-group">
							    <label class="col-sm-2 control-label">App名称</label>
							    <div class="col-sm-10">
							      <input type="text" class="form-control" id="appName" name="appName" placeholder="App名称" maxlength="10">
							    </div>
							  </div>
							  <div class="form-group">
							    <label class="col-sm-2 control-label">管理人员ID</label>
							    <div class="col-sm-9">
							      <input type="text" class="form-control" name="codeManager" placeholder="管理人员ID" maxlength="20"></input>
							    </div>
							    <a class="col-sm-1 glyphicon glyphicon-plus" href="#" onclick="addCodeManagerDiv();"></a>
							  </div>
							  <div id="addCodeManager"></div>
							  <div class="form-group">
							    <div class="col-sm-offset-2 col-sm-10">
							      <button type="button" id="submit" class="btn btn-default">注册</button>
							    </div>
							  </div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<script src="${ctx}/jquery/jquery.min.js"></script>
	<script src="${ctx}/bootstrap/js/bootstrap.min.js"></script>
	<script src="${ctx}/bootstrap/js/bootstrap-table.min.js"></script>
	<script src="${ctx}/bootstrap/local/bootstrap-table-zh-CN.min.js"></script>
	<script src="${ctx}/layer/layer.js"></script>
	<script type="text/javascript">
		
		$(function() {
			$("#submit").click(function() {
				var appCode = $("#appCode").val();
				if (null == appCode || undefined == appCode || '' == appCode) {
					layer.alert('申请的appCode不能为空', {icon : 0});
					return;
				}
				var appName = $("#appName").val();
				if (null == appName || undefined == appName || '' == appName) {
					layer.alert('申请的appName不能为空', {icon : 0});
					return;
				}
				$("[name='codeManager']").each(
					function(){
						var manager = $(this).val();
						if (null == manager || undefined == manager || '' == manager) {
							layer.alert('申请的每个管理员id不能为空', {icon : 0});
							return;
						}
					}
				);
				$.ajax({
		            type : "post",
		            url :  '${ctx}/app/register',
		            data:$('#registerForm').serialize(),
		            dataType : "json",
		            success : function(data) {
		                if (data.status=="1") {
		                    layer.msg(data.message, {icon : 1}, function() {
		                    	 window.location.href = "${ctx}/auth/toLogin";
			            		 var index = parent.layer.getFrameIndex(window.name);
			            		 parent.layer.close(index);
		                    });
		                } else {
		                    layer.msg(data.message, {icon : 0});
		                }
		            },
		            error : function(errorMsg) {
		                layer.msg('服务器未响应,请稍后再试', {icon : 3});
		            }
		        });
			});
		});
		function addCodeManagerDiv() {
			if ($("[name='codeManager']").length >= 5 ) {
				layer.alert('超过了设置管理员人数的最大阀值', {icon : 0});
				return;
			}
			var divStr = "<div class='form-group'><label class='col-sm-2 control-label'>管理人员ID</label><div class='col-sm-9'><input type='text' class='form-control' name='codeManager' placeholder='管理人员ID' maxlength='20'></input></div><a class='col-sm-1 glyphicon glyphicon-minus' href='#' onclick='removeCodeManagerDiv(this);'></a></div>";
			$(divStr).appendTo($('#addCodeManager'));
		};
		function removeCodeManagerDiv(t) {
			$(t).parent().remove();
		};
	</script>
</body>
</html>